﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EC_DataBase;

namespace EasyCheque.Welcome
{
    public partial class RegisterBankAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 界面处理。
            Panel_Calendar.Style["display"] = "none";
            Panel_Calendar.Style["position"] = "absolute";

            TextBox_BIRTHDAY.Text = DateTime.Now.ToString("yyyy-MM-dd");
            TextBox_Amount.Text = "10000";
            Label_CommitMessage.Visible = false;
        }

        protected void Calendar_InPanel_SelectionChanged(object sender, EventArgs e)
        {
            TextBox_BIRTHDAY.Text = Calendar_InPanel.SelectedDate.ToString("yyyy-MM-dd");
        }

        protected void Calendar_InPanel_VisibleMonthChanged(Object sender, MonthChangedEventArgs e)
        {
            Panel_Calendar.Style["display"] = "";
        }

        protected void Button_Register_Click(object sender, EventArgs e)
        {
            if (OperateDB.HasRows(OperateDB.TN_PERSON_ACCOUNT, "ACCOUNT_ID", TextBox_ACCOUNT_ID.Text))
            {
                System.Diagnostics.Debug.WriteLine("Already have one.");
                Label_CommitMessage.Visible = true;
                Label_CommitMessage.CssClass = "tipwrong";
                Label_CommitMessage.Text = "该银行帐户已注册。";
                return;
            }

            // 开始往数据库中加人。
            // 写表TN_PERSON_INFO。
            string secCode = Security.MD5.HexCompute(DateTime.Now.ToString(), System.Text.Encoding.ASCII);
            string[] valuesToInsert = new string[]
                {
                    TextBox_ACCOUNT_ID.Text, 
                    "花旗银行", 
                    TextBox_BIRTHDAY.Text, 
                    "储蓄账户", 
                    "NULL", 
                    "0", 
                    TextBox_Amount.Text, 
                    Security.MD5.HexCompute(TextBox_ACCOUNT_PASSWORD.Text, System.Text.Encoding.ASCII)
                };

            if (AccessDB.Insert(OperateDB.TN_ACCOUNT_INFO, valuesToInsert))
            {
                TextBox_ACCOUNT_ID.Text = "";
                Label_CommitMessage.Visible = true;
                Label_CommitMessage.CssClass = "tipok";
                Label_CommitMessage.Text = "登记成功。";
            }
            else
            {
                Label_CommitMessage.Visible = true;
                Label_CommitMessage.CssClass = "tipwrong";
                Label_CommitMessage.Text = "登记失败。";
            }
        }
    }
}
